//以下为修改jQuery Validation插件兼容Bootstrap的方法，没有直接写在插件中是为了便于插件升级
//         $.validator.setDefaults({
//             highlight: function (element) {
//                 $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
//             },
//             success: function (element) {
//                 element.closest('.form-group').removeClass('has-error').addClass('has-success');
//             },
//             errorElement: "span",
//             errorPlacement: function (error, element) {
//                 if (element.is(":radio") || element.is(":checkbox")) {
//                     error.appendTo(element.parent().parent().parent());
//                 } else {
//                     error.appendTo(element.parent());
//                 }
//             },
//             errorClass: "help-block m-b-none",
//             validClass: "help-block m-b-none"
//
//
//         });
$("#submit").on('click',function () {
    var index = layer.load(0, {shade: false});
    var form = document.getElementById('signupForm');
    fdata = new FormData(form);
    XHR = new XMLHttpRequest();
    XHR.open('POST','__MODULE__/WorkOrder/WorkOrder_add',true);
    XHR.onreadystatechange=function(){
        if(XHR.readyState == 4) {
            layer.close(indx);layer.msg(XHR.responseText, {time: 1000});
            setTimeout(function () {location.reload();}, 1100);
        }
    };
    XHR.send(fdata);
})

        //以下为官方示例
        $().ready(function () {
            // validate the comment form when it is submitted
            $("#commentForm").validate();

            // validate signup form on keyup and submit
            var icon = "<i class='fa fa-times-circle'></i> ";
            $("#signupForm").validate({
                rules: {
                    firstname: "required",

                    phone : {
                        required: true,
                        minlength : 11,
                        isMobile : true
                    },
                    content: {
                        required: true,
                        minlength:255
                    },

                    password: {
                        required: true,
                        minlength: 6
                    },
                    confirm_password: {
                        required: true,
                        minlength: 5,
                        equalTo: "#password"
                    },
                    email: {
                        required: true,
                        email: true
                    }
                },
                messages: {
                    phone : {
                        required : icon +"请输入手机号",
                        minlength : icon +"确认手机不能小于11个字符",
                        isMobile :icon + "请正确填写您的手机号码"
                    },

                    firstname: icon + "必填",
                    lastname: icon + "必填",

                    content: {
                        required: icon + "请输入您要咨询的问题",
                        minlength: icon + "问题必须255个字符以内"
                    },
                    email: icon + "请输入您的E-mail"
                }
            });

            // propose username by combining first- and lastname
            $("#username").focus(function () {
                var title = $("#title").val();
                var lastname = $("#lastname").val();
                if (title && lastname && !this.value) {
                    this.value = title + "." + lastname;
                }
            });
        });
